# cmake verson，指定cmake版本
cmake_minimum_required(VERSION 3.10)

# project name，指定项目的名称，一般和项目的文件夹名称对应
project(demo)

# 设置C++标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "-Wl,--no-as-needed ${CMAKE_CXX_FLAGS}")

# head file path，头文件目录
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../ubus/include )

# lib file path, 动态库目录
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../ubus/lib)

# Find all *.cpp files and store in list cpps
# GLOB这个参数不支持子目录， 用GLOB_RECURSE可以支持子目录。
file(GLOB cpps RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/src/*.c")

foreach(mainfile IN LISTS cpps)
    # Get file name without directory
    get_filename_component(mainname ${mainfile} NAME_WE)
    add_executable(${mainname} ${mainfile})
    target_link_libraries(${mainname} pthread json-c blobmsg_json json_script ubox ubus )
endforeach()
